/*
 * BanBu_DigiViewController
 * @description 本文件提供附近广播点击进入的广播详情界面的ViewController
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供附近广播点击进入的广播详情界面的ViewController
 */

#import "BanBu_DigiViewController.h"
#import "AppCommunicationManager.h"
#import "TKLoadingView.h"
#import "AppDataManager.h"
#import "BanBu_ChatToseePic.h"
#import "WXOpen.h"
#import "ShareViewController.h"
#import "BanBu_BroadcastTVC.h"

#import "BanBu_ImageView.h"
#import "BanBu_MWNavigationController.h"
#import "UIViewController+Animation.h"
#import "BanBu_PersonDataViewController.h"
#import "BanBu_UMengShareManager.h"
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"
#import "MBProgressHUD.h"
#import "BanBu_UMengShareManager.h"

#define kKoochat @"http://www.halfarea.com"
@interface BanBu_DigiViewController ()
@end
#define MIN(A,B)	({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
CGRect inputViewFrame ;
int cellNumber;//计算cell总高度的防止重复计算cell 高度
@implementation BanBu_DigiViewController

-(NSString*)getPreferredLanguage
{
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    NSArray* languages = [defs objectForKey:@"AppleLanguages"];
    NSString* preferredLang = [languages objectAtIndex:0];
    return preferredLang;
}
-(void)viewWillAppear:(BOOL)animated
{
    [UIView setAnimationsEnabled:YES];
    [super viewWillAppear:animated];
}
-(void)dealloc{
    [_shortUrl release],_shortUrl = nil;
    [_soundTime release],_soundTime = nil;
    [_sendSoundData release],_sendImageData = nil;
    [replyList release],replyList=nil;
    self.showPhotos = nil;
    self.chatView = nil;
    self.broadTableView = nil;
    self.inputTextView = nil;
    self.broadcast = nil;
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"playVoice" object:nil];
    [super dealloc];
    
}

- (id)initWithBroadcast:(NSDictionary *)broadcastDic{
    self = [super init];
    if (self) {
        
        _broadcast = [[NSMutableDictionary alloc] initWithDictionary:broadcastDic];
        _showPhotos=[[NSMutableArray alloc]initWithCapacity:10];
        
        //        NSLog(@"%@",_broadcast);
    }
    return self;
}

-(void)popself
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _praiseArr  = [[NSMutableArray   alloc] init];
    _praiseScroll = [[UIScrollView alloc] init];
    
    cellNumber =0;//回复列表的数目
    _shortUrl=[[NSMutableString alloc]init];
    
    inputViewFrame = CGRectMake(0, __MainScreen_Height-88, 320, 44);
    // Do any additional setup after loading the view.
    self.title = [MyAppDataManager IsMinGanWord:[MyAppDataManager theRevisedName:[[_broadcast valueForKey:@"userinfor"]valueForKey:@"pname"] andUID:[_broadcast valueForKey:@"userid"]]];
    
    if([MyAppDataManager.useruid isEqualToString:[_broadcast valueForKey:@"userid"]]){
        if([self  isHaveBroadcastTVC])
        {
            BanBu_NavButton *moreButton = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeNormal];
            moreButton.position = ButtonPositionRight;
            moreButton.frame = CGRectMake(0, 0, 50, 30);
            moreButton.titleLabel.font = [UIFont systemFontOfSize:14];
            [moreButton setImage:[UIImage imageNamed:@"delete_brocast.png"] forState:UIControlStateNormal];
            [moreButton addTarget:self action:@selector(moreAction) forControlEvents:UIControlEventTouchUpInside];
            UIBarButtonItem *rightItem = [[[UIBarButtonItem alloc] initWithCustomView:moreButton] autorelease];
            self.navigationItem.rightBarButtonItem = rightItem;
            [moreButton release];
        }
        
    }
    
    UITableView *aTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, __MainScreen_Height-88) style:UITableViewStylePlain];
    aTableView.delegate = self;
    aTableView.dataSource = self;
    aTableView.backgroundColor = [UIColor colorWithRed:255.0/255 green:250.0/255 blue:240.0/255 alpha:1.0];
    aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.broadTableView = aTableView;
    [self.view addSubview:aTableView];
    [aTableView release];
    
    
    BanBu_ImageView *img = [[BanBu_ImageView alloc] initWithBackGroundImageType:UIImageViewCreatTypeTable];
    self.broadTableView.backgroundView = img;
    
    UIImageView *bkView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -400, 320, 400)];
    bkView.image = [UIImage imageNamed:@"bgdark_profile.png"];
    [self.broadTableView addSubview:bkView];
    [bkView release];
    //TableViewHeader
    headerView = [[BanBu_ImageView alloc]initWithBackGroundImageType:UIImageViewCreatTypeCell imageName:@"listbg.png"];
    {
        NSDictionary *conDic = [[_broadcast valueForKey:@"actioninfor"] valueForKey:@"mcontent"];
        //头像
        UIButton *_iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _iconButton.frame = CGRectMake(10, 10, 38, 38);
        
        //        _iconButton.layer.borderColor = [[UIColor blackColor]CGColor];
        //        _iconButton.layer.borderWidth = 1.0;
        _iconButton.layer.cornerRadius = 19.0f;
        _iconButton.layer.masksToBounds = YES;
        [_iconButton setImageWithURL:[NSURL URLWithString:[[_broadcast valueForKey:@"userinfor"]valueForKey:@"uface"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:1];
        [_iconButton addTarget:self action:@selector(seeProfile) forControlEvents:UIControlEventTouchUpInside];
        
        [headerView addSubview:_iconButton];
        //名字
        UILabel *_nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(55, 10, 160, 17)];
        _nameLabel.backgroundColor = [UIColor clearColor];
        _nameLabel.text = [[_broadcast valueForKey:@"userinfor"] objectForKey:@"pname"];
        _nameLabel.font = [UIFont boldSystemFontOfSize:13];
        _nameLabel.textColor = [UIColor blackColor];
        [headerView addSubview:_nameLabel];
        [_nameLabel release];
        
        //距离标志
        UIImageView *_distanceBack = [[UIImageView alloc]initWithFrame:CGRectMake(55, 31, 10, 14)];
        NSString *signatureBackpath = [[NSBundle mainBundle] pathForResource:@"distance_mark" ofType:@"png"];
        _distanceBack.image =  [UIImage imageWithContentsOfFile:signatureBackpath];
        [headerView addSubview:_distanceBack];
        [_distanceBack release];
        
        //距离与到达时间
        UILabel *_distanceAndTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(68, 28, 160, 16)];
        _distanceAndTimeLabel.backgroundColor = [UIColor clearColor];
        _distanceAndTimeLabel.text =  [[_broadcast valueForKey:@"actioninfor"]objectForKey:@"admeter"];
        [_distanceAndTimeLabel sizeToFit];
        _distanceAndTimeLabel.font = [UIFont boldSystemFontOfSize:13];
        _distanceAndTimeLabel.textColor = UIColorWithRGB(150, 150, 150, 1.0);
        [headerView addSubview:_distanceAndTimeLabel];
        [_distanceAndTimeLabel release];
        
        //最新发布时间
        UILabel *_lastTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(235, 10, 75, 17)];
        _lastTimeLabel.backgroundColor = [UIColor clearColor];
        _lastTimeLabel.text = [MyAppDataManager getTheLastOnlineTime:[[_broadcast valueForKey:@"actioninfor"] valueForKey:@"mtime"]];
        _lastTimeLabel.textAlignment = kTextAlignmentRight;
        _lastTimeLabel.font = [UIFont boldSystemFontOfSize:13];
        _lastTimeLabel.textColor = UIColorWithRGB(150, 150, 150, 1.0);
        [headerView addSubview:_lastTimeLabel];
        [_lastTimeLabel release];
        
        //年龄和性别
        UIImageView * _sexImgV = [[UIImageView alloc]initWithFrame:CGRectMake(54 + _distanceAndTimeLabel.frame.size.width + 10, 31, 13, 13)];
        [headerView addSubview:_sexImgV];
        [_sexImgV release];
        
        //性别
        NSString *sex = [[_broadcast valueForKey:@"userinfor"] valueForKey:@"gender"];
        NSString *sexpath = [[NSBundle mainBundle] pathForResource:sex ofType:@"png"];
        _sexImgV.image = [UIImage imageWithContentsOfFile:sexpath];
        
        //年龄
        UILabel * _ageLabel = [[UILabel alloc]initWithFrame:CGRectMake(70 + _distanceAndTimeLabel.frame.size.width + 10, 31, 50, 16)];
        _ageLabel.backgroundColor = [UIColor clearColor];
        _ageLabel.font = [UIFont systemFontOfSize:13];
        _ageLabel.textColor = UIColorWithRGB(150, 150, 150, 1.0);
        [headerView addSubview:_ageLabel];
        [_ageLabel release];
        _ageLabel.text = [[_broadcast valueForKey:@"userinfor"] valueForKey:@"oldyears"];
        
        NSString *verifypath = [[NSBundle mainBundle] pathForResource:@"verify_card" ofType:@"png"];
        UIImageView * _verify = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:verifypath]];
        [_verify setFrame:CGRectMake(106 + _distanceAndTimeLabel.frame.size.width, 33, 15, 10)];
        _verify.hidden = YES;
        [headerView addSubview:_verify];
        
        UIImageView *_vipImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9, 9, 40, 42)];
        [headerView addSubview:_vipImageView];
        _sexImgV.image =  [UIImage imageWithContentsOfFile:sexpath];
        //vip等级显示
        if([[[_broadcast valueForKey:@"userinfor"]valueForKey:@"userlevel"] integerValue]>0)
        {
            NSString *path = [[NSBundle mainBundle] pathForResource:@"verify_vip" ofType:@"png"];
            _vipImageView.image =  [UIImage imageWithContentsOfFile:path];
            _verify.hidden = NO;
        }
        else
        {
            //视频认证用户
            if ([[[_broadcast valueForKey:@"userinfor"] valueForKey:@"verify"] boolValue])
            {
                NSString * verifySource = [NSString stringWithFormat:@"verify_%@",sex];
                NSString *path = [[NSBundle mainBundle] pathForResource:verifySource ofType:@"png"];
                _vipImageView.image =  [UIImage imageWithContentsOfFile:path];
                _verify.hidden = NO;
            }
            else
            {
                NSString *path = [[NSBundle mainBundle] pathForResource:@"verify_normal" ofType:@"png"];
                _vipImageView.image =  [UIImage imageWithContentsOfFile:path];
            }
        }
        
        
        
        //标签view
        UIView *_tagsView = [[UIView alloc]initWithFrame:CGRectZero];
        _tagsView.backgroundColor = [UIColor clearColor];
        [headerView addSubview:_tagsView];
        [_tagsView release];
        //文字（可选）
        _sayTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(55, 44, 235, 0)];
        //        _sayTextLabel.text = [MyAppDataManager IsInternationalLanguage:[MyAppDataManager IsMinGanWord:[conDic objectForKey:@"saytext"]]];
        _sayTextLabel.textColor = [UIColor blackColor];
        _sayTextLabel.font = [UIFont systemFontOfSize:13];
        _sayTextLabel.backgroundColor = [UIColor clearColor];
        CGFloat textLabelHeight = 0;
        if(![_sayTextLabel.text isEqualToString:@""]){
            NSString *saytext = [conDic objectForKey:@"saytext"];
            if([saytext rangeOfString:@"-->"].location != NSNotFound && [saytext rangeOfString:@"<--"].location != NSNotFound){
                NSInteger start=[saytext rangeOfString:@"<--"].location+3;
                NSInteger end = [saytext rangeOfString:@"-->"].location;
                _sayTextLabel.text = [saytext substringToIndex:start-3];
                textLabelHeight = [_sayTextLabel.text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 300) lineBreakMode:kTextLineBreakByTruncatingMiddle].height;
                
                _sayTextLabel.frame = CGRectMake(55, 55, 235, textLabelHeight);
                
                textLabelHeight += 5;
                
                NSString *tagString = [saytext substringWithRange:NSMakeRange(start, end-start)];
                NSArray *tagArray = [tagString componentsSeparatedByString:@" "];
                CGFloat height= 0,width = 0;
                for(int i= 0;i<tagArray.count;i++){
                    NSString *buttonTitle = [NSString stringWithFormat:@"#%@",[tagArray objectAtIndex:i]];
                    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
                    aButton.backgroundColor = [UIColor clearColor];
                    [aButton setTitle:buttonTitle forState:UIControlStateNormal];
                    aButton.titleLabel.font = [UIFont systemFontOfSize:13];
                    [aButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
                    CGFloat buttonLength = [buttonTitle sizeWithFont:[UIFont systemFontOfSize:13]].width;
                    if(width > 235-buttonLength){
                        width = 0;
                        height += 15;
                    }
                    aButton.frame = CGRectMake(width, height, buttonLength, 17);
                    width += buttonLength+5;
                    [aButton addTarget:self action:@selector(goSearchBroad:) forControlEvents:UIControlEventTouchUpInside];
                    [_tagsView addSubview:aButton];
                    
                }
                _tagsView.frame = CGRectMake(55, 55+textLabelHeight, 235, height+17);
                _tagsView.backgroundColor = [UIColor clearColor];
                textLabelHeight += height + 17;
                
                
            }
            else{
                _sayTextLabel.text = [MyAppDataManager IsInternationalLanguage:[conDic objectForKey:@"saytext"]];
                textLabelHeight = [_sayTextLabel.text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 300) lineBreakMode:kTextLineBreakByTruncatingMiddle].height;
                _sayTextLabel.frame = CGRectMake(55, 55, 235, textLabelHeight);
                
            }
        }
        
        _sayTextLabel.numberOfLines = 0;
        [headerView addSubview:_sayTextLabel];
        [_sayTextLabel release];
        
        
        
        //主图片
        if(textLabelHeight>0){
            textLabelHeight += 10;
        }
        CGFloat headImageViewHeight = 0;
        
        //        if(self.sendImageData){
        //           _headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 55+textLabelHeight, 300, 300)];
        //            headImageViewHeight = 300+10;
        //        }else{
        _headImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
        
        //        }
        
        //        _headImageView.image = [UIImage imageWithData:self.sendImageData];
        //        _headImageView.image = [UIImage imageNamed:@"photo_default.png"];
        _headImageView.userInteractionEnabled = YES;
        [headerView addSubview:_headImageView];
        [_headImageView release];
        
        //单击手势
        UITapGestureRecognizer *aTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(seeOriginalImage)];
        [_headImageView addGestureRecognizer:aTap];
        [aTap release];
        
        //播放按钮(可选)
        UIButton *_playButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _playButton.hidden = YES;
        _playButton.tag=213;
        [_playButton setImage:[UIImage imageNamed:@"播放语音_未按下.png"] forState:UIControlStateNormal];
        //        [_playButton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
        [headerView addSubview:_playButton];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(playAction:)];
        [_playButton addGestureRecognizer:tap];
        [tap release];
        
        NSArray *animationImages = [NSArray arrayWithObjects:@"feed_comment_player_pause_anim1.png",@"feed_comment_player_pause_anim2.png",@"feed_comment_player_pause_anim3.png", nil];
        NSMutableArray *images = [NSMutableArray arrayWithCapacity:6];
        for(NSString *path in animationImages){
            
            [images addObject:[UIImage imageNamed:path]];
        }
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(18+5, 7, 10, 12)];
        imageView.image = [UIImage imageNamed:@"audio_s_play.png"];
        imageView.userInteractionEnabled = YES;
        imageView.animationImages = images;
        imageView.animationDuration = 1.0;
        [_playButton addSubview:imageView];
        self.playingView = imageView;
        [imageView release];
        
        UILabel *aLabel = [[UILabel alloc]initWithFrame:CGRectMake(105-10-40, 3, 40, 20)];
        aLabel.backgroundColor = [UIColor clearColor];
        aLabel.textColor = [UIColor whiteColor];
        aLabel.font = [UIFont systemFontOfSize:14];
        aLabel.textAlignment= kTextAlignmentRight;
        
        [_playButton addSubview:aLabel];
        [aLabel release];
        
        //解base64的“mcontent”的内容
        
        for(NSDictionary *aDic in [conDic valueForKey:@"attach"]){
            if([[aDic valueForKey:@"type"] isEqualToString:@"sound"]){
                
                if(![[aDic valueForKey:@"content"] isEqualToString:@""]){
                    _playButton.hidden = NO;
                    _playButton.frame = CGRectMake( 160-105/2,_headImageView.frame.origin.y+ _headImageView.frame.size.height-13, 105, 26);
                    [_playButton setTitle:[NSString stringWithFormat:@"0,%@",[aDic valueForKey:@"content"]] forState:UIControlStateNormal];
                    
                    //语音的时间
                    if([aDic valueForKey:@"length"]){
                        aLabel.text = [NSString stringWithFormat:@"%@\"",[aDic valueForKey:@"length"]];
                        
                    }
                    
                    //有录音高度加button的一半
                    headImageViewHeight = 300+23;
                }
            }
            else if([[aDic valueForKey:@"type"] isEqualToString:@"image"]){
                
                _headImageView.frame = CGRectMake(10, 55+textLabelHeight, 300, 300) ;
                headImageViewHeight = 300+10;
                headImageString = [[NSString stringWithString:[aDic valueForKey:@"content"]] retain];
                [_headImageView setImageWithURL:[NSURL URLWithString:[NSString stringWithString:[aDic valueForKey:@"content"]]] placeholderImage:[UIImage imageNamed:@"photo_default.png"] andType:0];
                
            }
        }
        
        
        for(int i=0;i<4;i++)
        {
            UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
            aButton.tag = i+1;
            aButton.frame = CGRectMake(15+22.5+i*(71), 55+textLabelHeight+headImageViewHeight, 32, 32);
            UILabel *aLabel = [[UILabel alloc]initWithFrame:CGRectMake(15+22.5+i*(71)+32+6, aButton.frame.origin.y+16, 32, 16)];
            aLabel.backgroundColor = [UIColor clearColor];
            aLabel.tag = aButton.tag*10;
            //评论
            if(i==0)
            {
                if([[_broadcast valueForKey:@"comments"]integerValue]>0)
                {
                    aLabel.text = [NSString stringWithFormat:@"%@+",[_broadcast valueForKey:@"comments"]];
                }
            }
            //赞
            else if(i==1)
            {
                if([[[_broadcast valueForKey:@"actioninfor"] valueForKey:@"vote"]integerValue]>0)
                {
                    aLabel.text = [NSString stringWithFormat:@"%@+",[[_broadcast valueForKey:@"actioninfor"]valueForKey:@"vote"]];
                }
            }
            //分享
            else if(i==2)
            {
                //        [aLabel setHidden:YES];
                //       [aButton setHidden:YES];
                
                //                if([[[_broadcast valueForKey:@"actioninfor"]valueForKey:@"share"]integerValue]>0)
                //                {
                //                    aLabel.text = [NSString stringWithFormat:@"%@+",[[_broadcast valueForKey:@"actioninfor"]valueForKey:@"share"]];
                //                }
            }
            //举报
            else
            {
                //    aButton.frame = CGRectMake(15+22.5+2*(71), 55+textLabelHeight+headImageViewHeight, 32, 32);
                
                //     aLabel.frame = CGRectMake(15+22.5+2*(71)+32+6, aButton.frame.origin.y+16, 32, 16);
                if([MyAppDataManager.useruid isEqualToString:[_broadcast valueForKey:@"userid"]])
                {
                    aButton.hidden = YES;
                }
                
            }
            aLabel.font = [UIFont systemFontOfSize:12];
            aLabel.textColor = [UIColor redColor];
            [headerView addSubview:aLabel];
            [aLabel release];
            
            [aButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"addfun%d.png",i+1]] forState:UIControlStateNormal];
            [aButton addTarget:self action:@selector(addfun:) forControlEvents:UIControlEventTouchUpInside];
            [headerView addSubview:aButton];
        }
        
        //计算headerView的高度
        CGRect arect = headerView.frame;
        arect.size.height = 55+textLabelHeight+headImageViewHeight+32 + 15;
        headerView.frame = arect;
        
    }
    headerView.userInteractionEnabled = YES;
    //    headerView.image = [[UIImage imageNamed:@"listbg.png"] stretchableImageWithLeftCapWidth:2.0 topCapHeight:4.0];
    self.broadTableView.tableHeaderView = headerView;
    [headerView release];
    
    
    //toolbar
    {
        BanBu_ImageView *aView = [[BanBu_ImageView alloc]initWithBackGroundImageType:UIImageViewCreatTypeChat imageName:@"comment_publisher_bg.9.png"];
        
        aView.frame = CGRectMake(0,0, 320, 44);
        aView.userInteractionEnabled = YES;
        
        _textAndSoundBtn = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeChatVoice];
        _textAndSoundBtn.tag = 1020;
        _textAndSoundBtn.frame = CGRectMake(10, 7, 30, 30);
        _textAndSoundBtn.selected = NO;
        [_textAndSoundBtn addTarget:self action:@selector(changeBtn:) forControlEvents:UIControlEventTouchUpInside];
        [aView addSubview:_textAndSoundBtn];
        
        UITextView *aTextView = [[UITextView alloc]initWithFrame:CGRectMake(50, 7, 200, 30)];
        aTextView.layer.borderColor = [UIColor grayColor].CGColor;
        aTextView.layer.borderWidth = 1.0;
        aTextView.layer.cornerRadius = 13;
        //        aTextView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"edittext_normal_focus.9"]]
        //        aTextView.
        aTextView.textAlignment = kTextAlignmentLeft;
        aTextView.font = [UIFont systemFontOfSize:15];
        aTextView.delegate = self;
        [aTextView setContentInset:UIEdgeInsetsMake(-2, 5, 0, -5)];
        self.inputTextView = aTextView;
        [aView addSubview:self.inputTextView];
        [aTextView release];
        
        
        UILabel *placeHolder = [[UILabel alloc] init];
        placeHolder.textColor = [UIColor lightGrayColor];
        placeHolder.numberOfLines = 1;
        placeHolder.font = [UIFont systemFontOfSize:15];
        placeHolder.frame = CGRectMake(3, 5, 200, 24);
        self.placeHoldLabel = placeHolder;
        self.placeHoldLabel.text = NSLocalizedString(@"commendLabel", 评论);
        [self.inputTextView addSubview:placeHolder];
        [placeHolder release];
        //发送按钮
        sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        sendBtn.frame = CGRectMake(310-44, 4, 34, 34);
        [sendBtn setImage:[UIImage imageNamed:@"广播_发送.png"] forState:UIControlStateNormal];
        [sendBtn setImage:[UIImage imageNamed:@"广播_发送_按下.png"] forState:UIControlStateHighlighted];
        
        [sendBtn addTarget:self action:@selector(sendTextReply) forControlEvents:UIControlEventTouchUpInside];
        [aView addSubview:sendBtn];
        BanBu_ImageView *imageview2 = [[BanBu_ImageView alloc] initWithBackGroundImageType:UIImageViewCreatTypeChat imageName:@"comment_publisher_bg.9.png"];
        imageview2.frame = CGRectMake(0,0, 320, 44);
        imageview2.userInteractionEnabled = YES;
        //录音按钮
        voiceButton = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeChatLongPress];
        voiceButton.frame = CGRectMake(50, 7, 200+58, 30);
        voiceButton.layer.cornerRadius = 15;
        [voiceButton addTarget:self action:@selector(voiceTap) forControlEvents:UIControlEventTouchUpInside];
        //切换语音回复
        BanBu_NavButton  *voiceBtn = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeChatText];
        voiceBtn.frame = CGRectMake(10, 7, 30, 30);
        voiceBtn.tag = 1021;
        
        //        [voiceBtn setImage:[UIImage imageNamed:@"文字输入模式_未按下.png"] forState:UIControlStateNormal];
        //        [voiceBtn setImage:[UIImage imageNamed:@"文字输入模式_按下去.png"] forState:UIControlStateHighlighted];
        voiceBtn.selected = NO;
        [voiceBtn addTarget:self action:@selector(changeBtn:) forControlEvents:UIControlEventTouchUpInside];
        //        [aView addSubview:voiceBtn];
        UILabel *tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 3, 180, 24)];
        tipLabel.text = NSLocalizedString(@"longVoice", nil);
        tipLabel.font = [UIFont systemFontOfSize:15];
        tipLabel.backgroundColor = [UIColor clearColor];
        [voiceButton addSubview:tipLabel];
        [tipLabel release];
        [imageview2 addSubview:voiceButton];
        [imageview2 addSubview:voiceBtn];
        self.tabvoiceButton = voiceButton;
        
        UILongPressGestureRecognizer *aLongPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(voiceAction:)];
        [voiceButton addGestureRecognizer:aLongPress];
        [aLongPress release];
        [imageview2 addSubview:voiceButton];
        
        
        // 翻滚的输入框
        aView.tag = 1232;
        imageview2.tag = 1233;
        CFCube *cube = [[CFCube alloc] initWithFrame:CGRectMake(0, __MainScreen_Height-88,320,44)];
        self.chatView = cube;
        self.chatView.delegate = self;
        cube.visibleContentView = imageview2;
        cube.hiddenContentView = aView;
        [aView release];
        [imageview2 release];
        [self.view addSubview:cube];
        [cube release];
        
        //监听键盘高度
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardShowNotify:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardShowNotify:) name:UIKeyboardWillHideNotification object:nil];
    }
    //监听查看个人资料按钮和语音播放按钮
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playVoiceButton:) name:@"playVoice" object:nil];
    
    //    replyList = [[NSArray alloc]initWithArray:[_broadcast valueForKey:@"replylist"]];
    //2014年10月24日08:45:04 张毅飞 添加webview用于展示广播魔法文字⬇️
    _webviewDetail=[[UIWebView alloc]initWithFrame:CGRectMake(_sayTextLabel.frame.origin.x,_sayTextLabel.frame.origin.y, 235, 10)];
    _webviewDetail.delegate=self;
    [headerView addSubview:_webviewDetail];
    NSDictionary * kindDic=[[_broadcast valueForKey:@"actioninfor"] valueForKey:@"mcontent"];
    
    if ([[kindDic valueForKey:@"mkind"] isEqualToString:@"html"]) {
        _sayTextLabel.hidden=YES;
        _sayTextLabel.frame=CGRectZero;
        NSDictionary * dictionary=[[self.broadcast valueForKey:@"actioninfor"] valueForKey:@"mcontent"];
        NSString * htmlStr=[dictionary valueForKey:@"saytext"];
        NSData * data=[NSData dataFromBase64String:htmlStr];
        NSString * hhh=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        [_webviewDetail loadHTMLString:hhh baseURL:nil];
        [hhh release];
        
    }
    else
    {
        _webviewDetail.hidden=YES;
        _sayTextLabel.hidden = NO;
    }
    //⬆️

    
    //2014年10月27日17:33:16 by 张毅飞 分享⬇️
    //分享
#warning 没有国际化
    //**********************QuadCurveMenu******************//
    NSString *langauage=[MyAppDataManager getPreferredLanguage];
    if ([langauage isEqualToString:@"zh-Hans"]) {
        //sina
        QuadCurveMenuItem *sinaMenuItem = [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"UMS_sina_icon.png"] withIntro:NSLocalizedString(@"sinaPlatform", nil)];
        // tencentWeibo
        QuadCurveMenuItem *tencentMenuItem = [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"UMS_tencent_icon.png"] withIntro:NSLocalizedString(@"tencentPlatform", nil)];
        
        // qzone
        QuadCurveMenuItem *qzoneMenuItem = [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"UMS_qzone_icon.png"] withIntro:NSLocalizedString(@"qqZonePlatform", nil)];
        //wechatLine
        QuadCurveMenuItem *weLineMenuItem = [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"UMS_wechat_timeline_icon.png"] withIntro:NSLocalizedString(@"wechatTimelinePlatform", nil)];
        // wechatSession
        QuadCurveMenuItem *weSessionMenuItem = [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"UMS_wechat_session_icon.png"] withIntro:NSLocalizedString(@"wechatSessionPlatform", nil)];
        // renren
        QuadCurveMenuItem *renrenMenuItem= [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"UMS_renren_icon.png"] withIntro:NSLocalizedString(@"renrenPlatForm", nil)];
        
        //facebook
        QuadCurveMenuItem *FacebookMenuItem= [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"UMS_facebook_icon.png"] withIntro:@"Facebook"];
        //twitter
        QuadCurveMenuItem * TwitterItem= [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"UMS_twitter_icon.png"] withIntro:@"Twitter"];
        
        NSArray *menus = [NSArray arrayWithObjects:sinaMenuItem, tencentMenuItem, qzoneMenuItem, weLineMenuItem, weSessionMenuItem, renrenMenuItem,FacebookMenuItem,TwitterItem, nil];
        [FacebookMenuItem release];
        [TwitterItem release];        [sinaMenuItem release];
        [qzoneMenuItem release];
        [tencentMenuItem release];
        [weLineMenuItem release];
        [weSessionMenuItem release];
        [renrenMenuItem release];
        
        _menu = [[QuadCurveMenu alloc] initWithFrame:CGRectMake(0, 0, __MainScreen_Width, __MainScreen_Height - 44) menus:menus withShare:YES];
        _menu.delegate = self;
        [self.view addSubview:_menu];
        
    }
    else
    {
        QuadCurveMenuItem *facebookMenuItem1 = [[QuadCurveMenuItem alloc] initWithCustomImage:nil withIntro:nil];
        facebookMenuItem1.userInteractionEnabled=NO;
        //facebook
        QuadCurveMenuItem *facebookMenuItem = [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"facebookForm.png"] withIntro:@"Facebook"];
        //twitter
        QuadCurveMenuItem *twitterMenuItem = [[QuadCurveMenuItem alloc] initWithCustomImage:[UIImage imageNamed:@"twitterForm.png"] withIntro:@"Twitter"];
        NSArray *menus = [NSArray arrayWithObjects:facebookMenuItem1,facebookMenuItem,facebookMenuItem1,facebookMenuItem1,twitterMenuItem, nil];
        [facebookMenuItem release];
        [twitterMenuItem release];
        _menu = [[QuadCurveMenu alloc] initWithFrame:CGRectMake(0, 0, __MainScreen_Width, __MainScreen_Height - 44) menus:menus withShare:YES];
        _menu.delegate = self;
        [self.view addSubview:_menu];
        
    }
    //zyfzyfzyf⬆️
    //20141020
}
//zyfzyfzyf⬇️
#pragma mark - QuadCurveMenuDelegate选择的分享
- (void)quadCurveMenu:(QuadCurveMenu *)menu didSelectIndex:(NSInteger)idx
{
    NSLog(@"Select the index : %d",idx);
    [_menu setExpanding:NO];
    
    _hud=[[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:_hud];
    _hud.labelText=@"Loading";
    _hud.delegate=self;
    [_hud show:YES];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        
        NSString  *imageStr=[[[[[_broadcast valueForKey:@"actioninfor"] valueForKey:@"mcontent"] valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"content"];
        //2014年11月12日13:47:12 by 张毅飞 适配魔法广播分享
        NSString * kindstr=[[[_broadcast valueForKey:@"actioninfor"] valueForKey:@"mcontent"] valueForKey:@"mkind"];
        NSString * sayText;
        if ([kindstr isEqualToString:@"html"]) {
            sayText=[NSString stringWithFormat:@"%@",_shortUrl];
        }
        else
            sayText=[NSString stringWithFormat:@"%@ %@",[[[_broadcast valueForKey:@"actioninfor"] valueForKey:@"mcontent"] valueForKey:@"saytext"],_shortUrl];
        //⬆️
        UIImage * Shareimage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]]];
         NSString *urlStr=[NSString stringWithFormat:@"http://www.halfarea.com/shareto/broadview.html?actid=%@",[[_broadcast valueForKey:@"actioninfor" ] valueForKey:@"actid"]];
        //20141020⬇️
        dispatch_async(dispatch_get_main_queue(), ^{
            [_hud hide:YES];
            NSString *langauage=[MyAppDataManager getPreferredLanguage];
            if ([langauage isEqualToString:@"zh-Hans"]) {
                [[BanBu_UMengShareManager shareUMengManager] shareToPlatform:idx WithText:sayText WithImage:Shareimage WithClickUrlStr:urlStr WithPerformVC:self];
            }
            else
            {
                if (idx==1) {
                    [[BanBu_UMengShareManager shareUMengManager] shareToPlatform:ShareToFacebook WithText:sayText WithImage:Shareimage WithClickUrlStr:urlStr WithPerformVC:self];
                }
                else
                    [[BanBu_UMengShareManager shareUMengManager] shareToPlatform:ShareToTwitter WithText:sayText WithImage:Shareimage WithClickUrlStr:urlStr WithPerformVC:self];
            }
            //20141020⬆️
        });
        
    });
}

#pragma mark - MBprogressHUDdelegate
-(void)hudWasHidden:(MBProgressHUD *)hud
{
    [hud removeFromSuperview];
    [hud release];
    hud = nil;
    
}
#pragma mark -
//zyfzyfzyf⬆️

//点击标签
-(void)goSearchBroad:(UIButton *)sender{
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"xiangqingAction" object:sender];
    [self.navigationController popViewControllerAnimated:YES];
    
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if(!_isRefreshContent){
        NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:1];
        [pars setValue:[_broadcast valueForKey:@"actid"] forKey:@"actid"];
        [pars setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];
        [AppComManager getBanBuData:BanBu_Get_Broadcast par:pars delegate:self];
        _isRefreshContent = YES;
    }
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [AppComManager cancalHandlesForObject:self];
    
}

//更多功能

-(void)moreAction{
    
    UIActionSheet *deleteSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"cancelNotice", nil) destructiveButtonTitle:NSLocalizedString(@"deleteButton", nil) otherButtonTitles: nil];
    deleteSheet.tag = 1;
    [deleteSheet showInView:self.view];
    
}


//点击看原图
-(void)seeOriginalImage{
    MWPhoto *photo=[MWPhoto photoWithImage:_headImageView.image];
    
    [_showPhotos removeAllObjects];
    
    [_showPhotos addObject:photo];
    BanBu_ChatToseePic *broadSeePic = [[BanBu_ChatToseePic alloc]initWithDelegate:self];
    //    broadSeePic.displayActionButton = YES;
    broadSeePic.type = DrawTypeBroadcast;
    
    broadSeePic.shareArr = [NSMutableArray arrayWithObjects:_headImageView.image,headImageString, nil];
    BanBu_MWNavigationController *aNc = [[BanBu_MWNavigationController alloc]initWithRootViewController:broadSeePic];
    [self presentViewController:aNc animated:YES];
    [broadSeePic release];
    [aNc release];
    
}

#pragma mark - MWPhotoManager

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return 1;
}

- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _showPhotos.count)
        return [_showPhotos objectAtIndex:index];
    return nil;
}

//回复录音
-(void)voiceTap{
    
    [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"timeshortNoticte", nil) activityAnimated:NO duration:1.0];
    
}

-(void)voiceAction:(UILongPressGestureRecognizer *)sender{
    
    
    UIButton *button = (UIButton *)sender.view;
    if(button.selected)
    {
        CGPoint point = [sender locationInView:_recordView];
        if(sender.state == UIGestureRecognizerStateEnded)
        {
            button.selected = NO;
            [_recordView touchesEndInView:point];
            _recordView = nil;
        }else{
            
            [_recordView touchesMovedInView:point];
            
        }
        
        return;
    }
    
    //必须状态是begin才第二次录音，为了解决上次录音自动结束直接开始第二次录音问题
    if (sender.state == UIGestureRecognizerStateBegan)
    {
        button.selected = YES;
        _recordView = [[RecordView alloc]initWithFrame:CGRectMake(0, 0, 320, __MainScreen_Height+20)];
        NSString *fileName = @"huifu.amr";
        _recordView.audioPath = [AppComManager pathForMedia:fileName];
        _recordView.delegate = self;
        [self.navigationController.view addSubview:_recordView];
        [_recordView release];
    }
    
    
    
}

#pragma mark - RecordView Delegate

-(void)recordView:(RecordView *)recordView recordDidCompleted:(NSData *)audioData recordTime:(int)duration{
    
    voiceButton.selected = NO;
    if([audioData length]<100){
        
        [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"timeshortNoticte", nil) activityAnimated:NO duration:1.0];
        return;
    }
    _sendSoundData = [[NSData alloc]initWithData:audioData];
    _soundTime = [[NSString alloc]initWithFormat:@"%d",duration];
    if(_sendSoundData.length){
        
        
        NSMutableDictionary *sendDic = [NSMutableDictionary dictionaryWithCapacity:1];
        [sendDic setValue:@"amr" forKey:@"extname"];
        [AppComManager uploadBanBuBroadcastMedia:_sendSoundData mediaName:@"huifu.amr" par:sendDic delegate:self];
        [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"chuliNotice", nil) activityAnimated:YES];
        //        self.navigationController.view.userInteractionEnabled = NO;
        
    }
    
    
    //    NSLog(@"%d",duration);
    
}

//看主贴个人资料、播放语音
-(void)seeProfile{
    
    BanBu_PersonDataViewController *peopleFfofile = [[BanBu_PersonDataViewController alloc] initWithProfile:[_broadcast valueForKey:keyPersonalInfo]];
    peopleFfofile.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:peopleFfofile animated:YES];
    [peopleFfofile release];
}

#pragma 看回复个人资料
-(void)seeRelayProfile:(NSInteger)index{
    //    NSLog(@"%@",sender.titleLabel.text);
    NSDictionary *aDic = [NSDictionary dictionaryWithDictionary:[replyList objectAtIndex:index]];
    BanBu_PersonDataViewController *peopleFfofile = [[BanBu_PersonDataViewController alloc] initWithProfile:aDic];
    peopleFfofile.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:peopleFfofile animated:YES];
    [peopleFfofile release];
}
-(void)gotoProfile:(UIGestureRecognizer *)gesture
{
    NSDictionary *aDic = [NSDictionary dictionaryWithObjectsAndKeys:[[_praiseArr objectAtIndex:gesture.view.tag/886-1] valueForKey:@"userid"],@"userid",[NSArray array],@"facelist",nil];
    BanBu_PersonDataViewController *peopleFfofile = [[BanBu_PersonDataViewController alloc] initWithProfile:aDic];
    peopleFfofile.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:peopleFfofile animated:YES];
    [peopleFfofile release];
}
-(void)playAction:(UITapGestureRecognizer *)tap{
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"playVoice" object:(UIButton *)tap.view];
    
}

-(void)play:(UIButton *)sender{
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"playVoice" object:sender];
    
}
//2014年10月24日10:59:17 张毅飞 用于展示广播魔法文字⬇️
#pragma mark - 展示广播魔法文字
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGRect frame = webView.frame;
    frame.size.height = 1;
    webView.frame = frame;
    
    CGSize fittingSize=[webView sizeThatFits:CGSizeZero];
    frame.size=fittingSize;
    webView.frame=frame;
    _praiseScroll.contentSize=CGSizeMake(_praiseScroll.contentSize.width, _praiseScroll.contentSize.height+fittingSize.height);
    // _sayTextLabel.frame=CGRectMake(_sayTextLabel.frame.origin.x, _sayTextLabel.frame.origin.y, _sayTextLabel.frame.size.width, fittingSize.height);
    _headImageView.frame=CGRectMake(_headImageView.frame.origin.x, fittingSize.height+60, _headImageView.frame.size.width, _headImageView.frame.size.height);
    for(int i=0;i<4;i++)
    {
        UIButton * bbt=(UIButton *)[self.view viewWithTag:i+1];
        bbt.frame=CGRectMake(15+22.5+i*(71), 60+fittingSize.height+300+5, 32, 32);
        UILabel * alab=(UILabel *)[self.view viewWithTag:bbt.tag*10];
        alab.frame=CGRectMake(15+22.5+i*(71)+32+6, bbt.frame.origin.y+16, 32, 16);
    }
    // headerView.frame
    headerView.frame=CGRectMake(0, 0, 320, fittingSize.height+360+50);
    self.broadTableView.tableHeaderView=headerView;
    UIButton * playBtn=(UIButton *)[self.view viewWithTag:213];
    playBtn.frame=CGRectMake( 160-105/2,_headImageView.frame.origin.y+ _headImageView.frame.size.height-25, 105, 26);
    
    //国外webView内存泄露解决办法，
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDiskImageCacheEnabled"];//自己添加的，原文没有提到。
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitOfflineWebApplicationCacheEnabled"];//自己添加的，原文没有提到。
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    
}
//广播魔法文字⬆️

//附加功能按钮
#pragma mark - 评论、点赞、举报的按钮触发事件
-(void)addfun:(UIButton*)sender{
    [self.view endEditing:YES];
    if(sender.tag == 1){
        self.placeHoldLabel.text = @"";
        self.placeHoldLabel.tag = 0;
        [self.inputTextView becomeFirstResponder];
        [self.chatView setVisibleContentView:[self.chatView viewWithTag:1232]];
        [self.chatView setHiddenContentView:[self.chatView viewWithTag:1233]];
        
        //评论
        
    }else if(sender.tag == 2){
        
        //赞
        
        if([[_downloadDic valueForKey:@"iliked"] isEqualToString:@"n"])
        {
            NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:1];
            [pars setValue:[_broadcast valueForKey:@"actid"] forKey:@"actid"];
            [pars setValue:@"l" forKey:@"type"];
            [AppComManager getBanBuData:BanBu_Vote_Broadcast par:pars delegate:self];
            labelSelect = 2*10;
            
        }
        //重复赞
        else
        {
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"zan_failed", nil) activityAnimated:NO duration:1.0];
        }
    }
    else if(sender.tag == 3){
        //分享
        //20141020
        [_menu setExpanding:YES];
        //获取短网址
        NSString * shareUrl = [NSString stringWithFormat:@"%@/shareto/broadview.html?actid=%@",kKoochat,[[_broadcast valueForKey:@"actioninfor" ] valueForKey:@"actid"]];        [AppComManager getBanBuData:@"/_sys_dict/_get_short_url.php?jsonfrom=" par:[NSDictionary dictionaryWithObjectsAndKeys:shareUrl,@"url", nil] delegate:self];
        //20141020
    }else if(sender.tag == 4){
        //举报
        
        BanBu_ReportView *aReportView = [[BanBu_ReportView alloc]initWithFrame:CGRectMake(0, 0, 320, __MainScreen_Height+20) andType:REPORT_BROADCASR];
        aReportView.delegate = self;
        [self.navigationController.view addSubview:aReportView];
        [aReportView release];
        
        return;
        
        NSMutableArray *reportArr = [NSMutableArray array];
        if([UserDefaults valueForKey:@"reportList"]){
            [reportArr addObjectsFromArray:[UserDefaults valueForKey:@"reportList"]];
            BOOL isHave = NO;
            for(NSString *tem in reportArr){
                if([[_broadcast valueForKey:@"actid"] isEqualToString:tem]){
                    isHave = YES;
                    break;
                }
            }
            if(!isHave){
                NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:1];
                [pars setValue:[_broadcast valueForKey:@"actid"] forKey:@"actid"];
                [AppComManager getBanBuData:BanBu_Report_Broadcat par:pars delegate:self];
                //                self.navigationController.view.userInteractionEnabled = NO;
                [reportArr addObject:[_broadcast valueForKey:@"actid"]];
                [UserDefaults setValue:reportArr forKey:@"reportList"];
            }else{
                [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"reportNotice", nil) activityAnimated:NO duration:2.0];
                
            }
            
        }
        else{
            NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:1];
            [pars setValue:[_broadcast valueForKey:@"actid"] forKey:@"actid"];
            [AppComManager getBanBuData:BanBu_Report_Broadcat par:pars delegate:self];
            //            self.navigationController.view.userInteractionEnabled = NO;
            
            
            
            [reportArr addObject:[_broadcast valueForKey:@"actid"]];
            [UserDefaults setValue:reportArr forKey:@"reportList"];
        }
        
    }
}
#pragma mark - 举报的内容
- (void)reportAndPullBlack:(NSString *)message
{
    //2014年09月25日11:43:37 记录举报过的广播，列表显示时去掉
    NSMutableArray *reportArr = [NSMutableArray array];
    if([UserDefaults valueForKey:@"reportList"])
    {
        [reportArr addObjectsFromArray:[UserDefaults valueForKey:@"reportList"]];
        BOOL isHave = NO;
        for(NSString *tem in reportArr)
        {
            if([[_broadcast valueForKey:@"actid"] isEqualToString:tem])
            {
                isHave = YES;
                break;
            }
        }
        if(!isHave)
        {
            [reportArr addObject:[_broadcast valueForKey:@"actid"]];
            [UserDefaults setValue:reportArr forKey:@"reportList"];
        }
    }
    else
    {
        [reportArr addObject:[_broadcast valueForKey:@"actid"]];
        [UserDefaults setValue:reportArr forKey:@"reportList"];
    }
    NSLog(@"%@",message);
    NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:2];
    [pars setValue:[_broadcast valueForKey:@"actid"] forKey:@"actid"];
    [pars setValue:message forKey:@"saytext"];
    [AppComManager getBanBuData:BanBu_Report_Broadcat par:pars delegate:self];
    self.navigationController.view.userInteractionEnabled = NO;
    [TKLoadingView showTkloadingAddedTo:self.navigationController.view  title:NSLocalizedString(@"chuliNotice", nil) activityAnimated:YES];
    
}
//回复文字与语音的切换
#pragma mark - 回复文字与语音的切换
-(void)changeBtn:(UIButton *)sender{
    if(sender.tag == 1020){
        [self.inputTextView resignFirstResponder];
        [self keyboardReset];
        [self.chatView flipWithStyle:CFCubeFlipUp];
        self.chatView.frame = CGRectMake(0, __MainScreen_Height-88, 320, 44);
        
    }else{
        [self.chatView flipWithStyle:CFCubeFLipDown];
        [UIView animateWithDuration:0.25 animations:^{
            //            self.chatView.backgroundColor = [UIColor redColor];
            self.chatView.frame = inputViewFrame;
            //            self.chatView.frame = CGRectMake(0, __MainScreen_Height-88-216, 320, 44);
        }];
        //        [self.inputTextView becomeFirstResponder];
    }
}

//监听键盘的收起展开
-(void)keyboardReset{
    [self.inputTextView resignFirstResponder];
    inputViewFrame = self.chatView.frame;
}

-(void)keyboardShowNotify:(NSNotification *)notification{
    
    CGFloat keyboardHeight = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size.height;
    if([notification.name isEqualToString:UIKeyboardWillHideNotification]){
        keyboardHeight = 0;
    }
    [UIView animateWithDuration:0.25 animations:^{
        
        CGRect frame = self.chatView.frame;
        if(keyboardHeight != 0)
        {
            frame.origin.y = __MainScreen_Height-44-keyboardHeight-self.chatView.frame.size.height;
        }
        else
        {
            frame.origin.y = __MainScreen_Height-self.chatView.frame.size.height-keyboardHeight-44;
        }
        self.chatView.frame = frame;
        frame = self.broadTableView.frame;
        if(__MainScreen_Height-headerView.frame.size.height-cellHeight-keyboardHeight-88>0||!keyboardHeight)
        {
            frame.origin.y = 0;
        }
        else
        {
            frame.origin.y = -keyboardHeight;
        }
        
        if(replyList.count)
        {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:replyList.count inSection:0];
            [self.broadTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        }
        self.broadTableView.frame = frame;
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//发送文字回复

-(void)sendTextReply{
    
    if(![[self.inputTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]isEqualToString:@""]){
        [self keyboardReset];
        NSMutableDictionary *abrd = [NSMutableDictionary dictionaryWithCapacity:2];
        [abrd setValue:[MyAppDataManager IsMinGanWord:self.inputTextView.text] forKey:@"saytext"];
        //    [abrd setValue:[NSArray array] forKey:@"attach"];
        
        if(self.placeHoldLabel.text.length && (![self.placeHoldLabel.text isEqualToString:NSLocalizedString(@"commendLabel", nil)]))
        {
            [abrd setValue:[self.placeHoldLabel.text substringFromIndex:1] forKey:@"topname"];
            [abrd setValue:[NSNumber numberWithInteger:self.placeHoldLabel.tag/11] forKey:@"touid"];
        }
        NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:1];
        [pars setValue:[_broadcast valueForKey:@"actid"] forKey:@"replyid"];
        [pars setValue:abrd forKey:@"says"];
        [AppComManager getBanBuData:BanBu_Reply_Broadcast par:pars delegate:self];
        [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"sendingNotice", nil) activityAnimated:YES];
    }
    
    self.inputTextView.text = @"";
    
    CGRect frame = _inputTextView.frame;
    frame.size.height = 30;
    _inputTextView.frame= frame;
    
    
    
    self.chatView.frame = CGRectMake(0, __MainScreen_Height-88,320,44);
    
    //    [self textViewDidChange:self.inputTextView];
    
    
    CGRect sendbuttonFrame  =  sendBtn.frame;
    sendbuttonFrame.origin.y = self.chatView.frame.size.height-38;
    sendBtn.frame = sendbuttonFrame;
    self.previousTextViewContentHeight = 34;
    
}

#pragma mark - UIActionSheetDelegate

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(actionSheet.tag == 1){
        if(buttonIndex == 0){
            [[NSNotificationCenter defaultCenter]postNotificationName:@"delete_Broadcast" object:[_broadcast valueForKey:@"actid"]];
            
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    
}


- (void) performPublishAction:(void (^)(void)) action {
    // we defer request for permission to post to the moment of post, then we check for the permission
    if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
        // if we don't already have the permission, then we request it now
        [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                                   defaultAudience:FBSessionDefaultAudienceFriends
                                                 completionHandler:^(FBSession *session, NSError *error) {
                                                     if (!error) {
                                                         [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"sendingNotice", nil) activityAnimated:YES];
                                                         
                                                         action();
                                                     }
                                                     //For this example, ignore errors (such as if user cancels).
                                                 }];
    } else {
        [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"sendingNotice", nil) activityAnimated:YES];
        
        action();
    }
    
}
- (void)showAlert:(NSString *)message
           result:(id)result
            error:(NSError *)error {
    
    NSString *alertMsg;
    NSString *alertTitle;
    if (error) {
        alertMsg = error.localizedDescription;
        alertTitle = @"Error";
    } else {
        NSDictionary *resultDict = (NSDictionary *)result;
        alertMsg = [NSString stringWithFormat:@"Successfully posted '%@'.\nPost ID: %@",
                    message, [resultDict valueForKey:@"id"]];
        alertTitle = @"Success";
    }
    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
                                                        message:alertMsg
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
    [alertView show];
}


- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    
    
    TKLoadingView *indictor = nil;
    for(indictor in self.view.subviews)
        if([indictor isKindOfClass:[TKLoadingView class]])
        {
            [indictor setActivityAnimating:NO withShowMsg:NSLocalizedString(@"shareSuccess", nil)];
            [indictor dismissAfterDelay:1.0 animated:YES];
        }
    
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    
    TKLoadingView *indictor = nil;
    for(indictor in self.view.subviews)
        if([indictor isKindOfClass:[TKLoadingView class]])
        {
            [indictor setActivityAnimating:NO withShowMsg:NSLocalizedString(@"errcode_fail", nil)];
            [indictor dismissAfterDelay:1.0 animated:YES];
        }
}


- (void)storeAccessToken:(NSString *)accessToken {
    [[NSUserDefaults standardUserDefaults]setObject:accessToken forKey:@"SavedAccessHTTPBody"];
}

- (NSString *)loadAccessToken {
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"SavedAccessHTTPBody"];
}

#pragma mark - TextView Delegate

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if([text isEqualToString:@"\n"]){
        //        [textView setContentSize:CGSizeMake(textView.contentSize.width, self.previousTextViewContentHeight)];
        //        self.previousTextViewContentHeight = 36;
        return NO;
    }
    if (textView.text.length > 300)
    {
        [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"twentyEnough", nil) activityAnimated:NO duration:1.0];
        textView.text = [textView.text substringToIndex:300];
        return NO;
    }
    return YES;
    
}



#pragma mark - ScrollView Delegate

//-(void)scrollToBottom_tableView
//{
//    NSArray *sections = [[self.broadTableView fetchedResultsController] sections];
//    if([sections count]<=0) return;
//    id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:0];
//    //NSLog(@"numher:%d",sectionInfo.numberOfObjects);
//    if (sectionInfo.numberOfObjects<=0) {
//        return;
//    }
//    NSIndexPath * ndxPath= [NSIndexPath indexPathForRow:sectionInfo.numberOfObjects-1 inSection:0];
//    [mTableView scrollToRowAtIndexPath:indxPath atScrollPosition:UITableViewScrollPositionBottom  animated:NO];
//
//}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    if([self.inputTextView isFirstResponder]){
        
        [self keyboardReset];
    }
}

#pragma mark - TalbeView DataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return replyList.count+1;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(!indexPath.row)
    {
        if(_praiseArr.count)
            return 40;
        else
            return 0;
    }
    NSDictionary *replyDic = [NSDictionary dictionaryWithDictionary:[replyList objectAtIndex:indexPath.row-1]];
    NSDictionary *conDic = [AppComManager getAMsgFrom64String:[replyDic valueForKey:@"mcontent"]];
    if([[conDic valueForKey:@"saytext"] length])
    {
        NSString *nametext = nil;
        if([[conDic valueForKey:@"topname"] length])
        {
            nametext = [NSString stringWithFormat:@"RE @%@: ",[conDic valueForKey:@"topname"]];
            if(nametext.length >18)
            {
                nametext = [NSString stringWithFormat:@"RE @%@: ",[[conDic valueForKey:@"topname"] substringToIndex:13]];
            }
        }
        
        NSString *sayText = [NSString stringWithFormat:@"%@%@",nametext,[conDic valueForKey:@"saytext"]];
        
        CGFloat sayTextHeight = [sayText sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 100) lineBreakMode:kTextLineBreakByWordWrapping].height;
        
        if(cellNumber<=indexPath.row)
        {
            cellHeight += 38+sayTextHeight;
        }
        cellNumber++;
        return 38+sayTextHeight;
    }
    else
    {
        return 55;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    for (UIImageView *image in _praiseScroll.subviews) {
    //        [image removeFromSuperview];
    //    }
    if(!indexPath.row)
    {
        static NSString *cellIdentifier = @"BroadcastCellPraise";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if(cell == nil)
        {
            cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        if(_praiseArr.count)
        {
            _praiseScroll.contentSize = CGSizeMake(35*_praiseArr.count + 58, 40);
            _praiseScroll.frame = CGRectMake(40, 0, __MainScreen_Width, 40);
            
            UIImageView *zanImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"praiseList.png"]];
            zanImage.frame = CGRectMake(8, 8, 20, 20);
            [cell.contentView addSubview:zanImage];
            NSLog(@"%@",_praiseArr);
            for (int i=0; i<_praiseArr.count; i++)
            {
                UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(3+i*37, 3, 30, 30)];
                [img setImageWithURL:[NSURL URLWithString:[[_praiseArr objectAtIndex:i] valueForKey:@"uface"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:0];
                img.layer.cornerRadius = 15.0;
                img.layer.masksToBounds = YES;
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoProfile:)];
                tap.numberOfTapsRequired = 1;
                img.tag = (i+1)*886;
                img.userInteractionEnabled = YES;
                [img addGestureRecognizer:tap];
                [_praiseScroll addSubview:img];
                [img release];
            }
            
            UIView *lineView = [[UIView alloc] init];
            lineView.frame = CGRectMake(-1, 39, 322, 1);
            lineView.backgroundColor = [UIColor colorWithRed:224.0/255 green:224.0/255 blue:224.0/255 alpha:1.0];
            [cell.contentView addSubview:lineView];
            [cell.contentView addSubview:_praiseScroll];
            [lineView release];
        }
        return cell;
        
    }
    else
    {
        static NSString *cellIdentifier = @"BroadcastCell";
        BanBu_DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if(cell == nil){
            cell = [[[BanBu_DetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        NSDictionary *replyDic = [NSDictionary dictionaryWithDictionary:[replyList objectAtIndex:indexPath.row-1]];
        NSDictionary *conDic = [AppComManager getAMsgFrom64String:[replyDic valueForKey:@"mcontent"]];
        
        [cell setAvatar:[replyDic valueForKey:@"uface"]];
        cell.iconButton.tag = indexPath.row-1;
        cell.nameLabel.text = [replyDic objectForKey:@"pname"];
        cell.nameLabel.frame = CGRectMake(55, 10, 180, cell.nameLabel.frame.size.height);
        
        cell.lastTimeLabel.text = [MyAppDataManager getTheLastOnlineTime:[replyDic valueForKey:@"mtime"]];
        cell.lastTimeLabel.frame = CGRectMake(235, 10, 75, 17);
        
        [cell setSaytext:conDic];
        
        
        
        cell.playButton.frame = CGRectZero;
        cell.timeLabel.frame = CGRectZero;
        [cell.playButton setTitle:@"" forState:UIControlStateNormal];
        
        
        for(NSDictionary *aDic in [conDic valueForKey:@"attach"]){
            if([[aDic valueForKey:@"type"] isEqualToString:@"sound"]){
                
                if(![[aDic valueForKey:@"content"]isEqualToString:@""]){
                    cell.playButton.hidden = NO;
                    CGFloat nameWidth = [cell.nameLabel.text sizeWithFont:cell.nameLabel.font constrainedToSize:CGSizeMake(100, 17) lineBreakMode:kTextLineBreakByTruncatingTail].width;
                    cell.nameLabel.frame = CGRectMake(55, 19, nameWidth, cell.nameLabel.frame.size.height);
                    cell.lastTimeLabel.frame = CGRectMake(235, 19, 75, 17);
                    
                    [cell.playButton setTitle:[NSString stringWithFormat:@"1,%@",[[[conDic valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"content"]] forState:UIControlStateNormal];
                    [cell.playButton setImage:[UIImage imageNamed:@"广播详情-复选框-播放.png"] forState:UIControlStateNormal];
                    //                    NSString *replyName = [conDic valueForKey:@"topname"];
                    //                    cell.replyNameLabel.text = replyName.length?[NSString stringWithFormat:@"@%@ ",[conDic valueForKey:@"topname"]]:@"";
                    //                    float replyNameWidth = [cell.replyNameLabel.text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(80, 17) lineBreakMode:NSLineBreakByTruncatingMiddle].width;
                    //                    cell.replyNameLabel.frame = CGRectMake(cell.nameLabel.frame.origin.x+nameWidth+10, 15, replyNameWidth, 17);
                    //                    cell.replyNameLabel.tag = [[conDic valueForKey:@"touid"] integerValue]*22;
                    
                    
                    cell.playButton.frame = CGRectMake(cell.nameLabel.frame.origin.x+nameWidth+10, 15, 60, 25);
                    if([aDic valueForKey:@"length"]){
                        cell.timeLabel.text = [NSString stringWithFormat:@"%@\"",[[aDic valueForKey:@"length"] floatValue]>0?[aDic valueForKey:@"length"]:@"1"];
                    }
                    cell.timeLabel.frame = CGRectMake(cell.playButton.frame.origin.x+60-10-25, cell.playButton.frame.origin.y+2, 25, 20);
                }
            }
            
        }
        __block id bself = self;
        [cell setSelectPeopleCallBack:^(NSInteger tag)
         {
             [bself seeRelayProfile:tag];
         }];
        return cell;
    }
    
}

#pragma mark - TableView Delegate

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        return;
    }
    if([self.inputTextView isFirstResponder])
    {
        [self.inputTextView resignFirstResponder];
        return;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    self.inputTextView.text = @"";
    [self.inputTextView becomeFirstResponder];
    [self.chatView setVisibleContentView:[self.chatView viewWithTag:1232]];
    [self.chatView setHiddenContentView:[self.chatView viewWithTag:1233]];
    
    NSDictionary *replyDic = [NSDictionary dictionaryWithDictionary:[replyList objectAtIndex:indexPath.row-1]];
    self.placeHoldLabel.tag = [[replyDic valueForKey:@"userid"] integerValue]*11;//把@对方的userid*111存入tag中 方便调用
    self.placeHoldLabel.text= [NSString stringWithFormat:@"@%@",[replyDic valueForKey:@"pname"]];//@对方的名字
    self.placeHoldLabel.hidden = NO;
}



// 语音的播放及动画
-(void)animation:(UIButton *)animationBtn
{
    if(animationBackgroundView){
        [animationBackgroundView removeFromSuperview];
    }
    
    animationBackgroundView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 60, 25)];
    animationBackgroundView.userInteractionEnabled = YES;
    [animationBackgroundView setImage:[UIImage imageNamed:@"广播详情-复选框-播放_空.png"]];
    
    
    NSArray *animationImages = [NSArray arrayWithObjects:@"feed_comment_player_pause_anim1.png",@"feed_comment_player_pause_anim2.png",@"feed_comment_player_pause_anim3.png", nil];
    NSMutableArray *images = [NSMutableArray arrayWithCapacity:3];
    for(NSString *path in animationImages)
    {
        [images addObject:[UIImage imageNamed:path]];
    }
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    imageView.userInteractionEnabled = YES;
    imageView.animationImages = images;
    imageView.animationDuration = 1.0;
    imageView.animationImages = images;
    imageView.animationDuration = 1.0;
    imageView.frame = CGRectMake(13, 6.5, 10, 12);
    
    
    imageView.userInteractionEnabled = YES;
    
    imageView.backgroundColor = [UIColor clearColor];
    [animationBackgroundView addSubview:imageView];
    [imageView startAnimating];
    [imageView release];
    
    [animationBtn addSubview:animationBackgroundView];
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stopPlay:)];
    [animationBackgroundView addGestureRecognizer:tap];
    [tap release];
    
    
}

-(void)stopPlay:(UITapGestureRecognizer *)tap{
    [_player stop];
    [tap.view removeFromSuperview];
    
    
}

-(void)playVoiceButton:(NSNotification *)notifi{
    
    UIButton *sender = (UIButton *)[notifi object];
    
    _voiceButton = sender;
    NSArray *voiceArr = [_voiceButton.titleLabel.text componentsSeparatedByString:@","];
    if(![FileManager fileExistsAtPath:[AppComManager pathForMedia:[voiceArr lastObject]]]){
        
        [AppComManager getBanBuMedia:[voiceArr lastObject] delegate:self];
        [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"loadingNotice", nil) activityAnimated:YES];
    }else{
        
        if([[voiceArr objectAtIndex:0]boolValue]){
            
            
            if(_player){
                [self.playingView stopAnimating];
                
                [_player release],_player = nil;
            }
            NSData *aData = [NSData dataWithContentsOfFile:[AppComManager pathForMedia:[voiceArr lastObject]]];
            //            NSLog(@"%@",[AppComManager pathForMedia:[voiceArr lastObject]]);
            _player = [[AVAudioPlayer alloc]initWithData:aData error:nil];
            _player.delegate = self;
            _player.volume = 1.0;
            [_player prepareToPlay];
            
            [_player play];
            [_playHUD startAnimating];
            //        sender.hidden = YES;
            if([_player isPlaying]){
                [self animation:sender];
            }
        }else{
            
            if([self.playingView isAnimating]){
                
                
                [self.playingView stopAnimating];
                if(_player){
                    
                    [_player release],_player = nil;
                }
                return;
            }
            
            NSData *aData = [NSData dataWithContentsOfFile:[AppComManager pathForMedia:[voiceArr lastObject]]];
            
            _player = [[AVAudioPlayer alloc]initWithData:aData error:nil];
            _player.delegate = self;
            _player.volume = 1.0;
            [_player prepareToPlay];
            
            [_player play];
            [_playHUD startAnimating];
            //        sender.hidden = YES;
            if([_player isPlaying]){
                //            [self animation:sender];
                [self.playingView startAnimating];
            }
        }
        
    }
    
}


//上传

#pragma mark - BanBuUploadRequsetDelegate

- (void)banbuUploadRequest:(NSDictionary *)resDic didFinishedWithError:(NSError *)error{
    //    NSLog(@"%@",resDic);
    
    self.navigationController.view.userInteractionEnabled = YES;
    [TKLoadingView dismissTkFromView:self.view animated:NO afterShow:0.0];
    if(error){
        [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"uploadFailNotice", nil) activityAnimated:NO duration:2.0];
    }
    if([[resDic valueForKey:@"ok"] boolValue]){
        if([[resDic valueForKey:@"requestname"] isEqualToString:@"huifu.amr"]){
            [FileManager removeItemAtPath:[AppComManager pathForMedia:@"huifu.amr"] error:nil];
            
            NSMutableDictionary *abrd = [NSMutableDictionary dictionaryWithCapacity:2];
            [abrd setValue:@"" forKey:@"saytext"];
            [abrd setValue:[NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:@"sound",@"type",[resDic valueForKey:@"fileurl"],@"content",_soundTime,@"length", nil]] forKey:@"attach"];
            NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:1];
            [pars setValue:[_broadcast valueForKey:@"actid"] forKey:@"replyid"];
            [pars setValue:abrd forKey:@"says"];
            [AppComManager getBanBuData:BanBu_Reply_Broadcast par:pars delegate:self];
            //            self.navigationController.view.userInteractionEnabled = NO;
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"sendingNotice", nil) activityAnimated:YES];
        }
    }
}


//下载语音

#pragma mark - BanBuDownloadRequest

- (void)banbuDownloadRequest:(NSDictionary *)resDic didFinishedWithError:(NSError *)error{
    //    NSLog(@"%@",resDic);
    
    NSArray *voiceArr = [_voiceButton.titleLabel.text componentsSeparatedByString:@","];
    
    
    [TKLoadingView dismissTkFromView:self.navigationController.view animated:NO afterShow:0.0];
    if([[resDic valueForKey:@"ok"]boolValue]){
        
        if([[voiceArr objectAtIndex:0]boolValue]){
            
            
            if(_player){
                [self.playingView stopAnimating];
                
                [_player release],_player = nil;
            }
            NSData *aData = [NSData dataWithContentsOfFile:[AppComManager pathForMedia:[voiceArr lastObject]]];
            
            _player = [[AVAudioPlayer alloc]initWithData:aData error:nil];
            _player.delegate = self;
            _player.volume = 1.0;
            [_player prepareToPlay];
            
            [_player play];
            [_playHUD startAnimating];
            //        sender.hidden = YES;
            if([_player isPlaying]){
                [self animation:_voiceButton];
            }
        }
        else{
            
            if([self.playingView isAnimating]){
                
                
                [self.playingView stopAnimating];
                if(_player){
                    
                    [_player release],_player = nil;
                }
                return;
            }
            
            NSData *aData = [NSData dataWithContentsOfFile:[AppComManager pathForMedia:[voiceArr lastObject]]];
            
            _player = [[AVAudioPlayer alloc]initWithData:aData error:nil];
            _player.delegate = self;
            _player.volume = 1.0;
            [_player prepareToPlay];
            
            [_player play];
            [_playHUD startAnimating];
            //        sender.hidden = YES;
            if([_player isPlaying]){
                //            [self animation:sender];
                [self.playingView startAnimating];
            }
        }
    }else{
        //        [TKLoadingView showTkloadingAddedTo:self.view title:@"下载失败" activityAnimated:NO duration:1.0];
    }
}

//播放完毕

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    
    [_player stop];
    if(animationBackgroundView){
        [animationBackgroundView removeFromSuperview];
    }
    if([self.playingView isAnimating]){
        [self.playingView stopAnimating];
    }
    //    [[_voiceButton.subviews lastObject]removeFromSuperview];
}

-(BOOL)isHaveBroadcastTVC
{
    for(BanBu_BroadcastTVC  * broad in self.navigationController.viewControllers)
    {
        if([broad isKindOfClass:[BanBu_BroadcastTVC class]]||[broad isKindOfClass:[BanBu_PersonDataViewController class]])
        {
            return YES;
        }
    }
    return NO;
}
#pragma mark - BanBu_Request

-(void)banbuRequestDidFinished:(NSDictionary *)resDic error:(NSError *)error
{//20141020
    if ([[resDic valueForKey:@"fc"] isEqualToString:@"get_short_url"]) {
        _shortUrl=[resDic valueForKey:@"shorturl"];
        [_shortUrl retain];
    }
    //20141020
    self.navigationController.view.userInteractionEnabled = YES;
    [TKLoadingView dismissTkFromView:self.navigationController.view animated:YES afterShow:0.0];
    if(error)
    {
        if([error.domain isEqualToString:BanBuDataformatError]){
            [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:2.0];
        }else{
            [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:2.0];
        }
        return;
    }
    
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Vote_Broadcast])
    {
        if([[resDic valueForKey:@"ok"] isEqual:@"y"])
        {
            [_downloadDic setValue:@"y" forKey:@"iliked"];
            [_praiseArr addObject:[NSDictionary dictionaryWithObjectsAndKeys:MyAppDataManager.useruid,@"userid",[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"],@"uface",nil]];
            [_broadTableView reloadData];
            UILabel *aLabel = (UILabel *)[self.view viewWithTag:labelSelect];
            if(labelSelect == 20){
                
                aLabel.text = [NSString stringWithFormat:@"%d+",_praiseArr.count];                if([self isHaveBroadcastTVC])
                {
                    NSMutableDictionary *pardic;
                    if(_isUserBroad)
                    {
                        pardic = [[NSMutableDictionary alloc]initWithDictionary:[MyAppDataManager.friendDos objectAtIndex:self.selectSection]];
                    }
                    else
                    {
                        pardic = [[NSMutableDictionary alloc]initWithDictionary:[MyAppDataManager.nearDos objectAtIndex:self.selectSection]];
                    }
                    
                    NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:[pardic valueForKey:@"actioninfor"]];
                    [dic setValue:[aLabel.text substringToIndex:aLabel.text.length-1] forKey:@"vote"];
                    [pardic setValue:dic forKey:@"actioninfor"];
                    if(_isUserBroad)
                    {
                        [MyAppDataManager.friendDos replaceObjectAtIndex:self.selectSection withObject:pardic];
                    }
                    else
                    {
                        [MyAppDataManager.nearDos replaceObjectAtIndex:self.selectSection withObject:pardic];
                    }
                    for(BanBu_BroadcastTVC  * broad in self.navigationController.viewControllers)
                    {
                        if(([broad isKindOfClass:[BanBu_BroadcastTVC class]]||[broad isKindOfClass:[BanBu_PersonDataViewController class]]))
                        {
                            [broad.tableView reloadData];
                        }
                    }
                    [dic release];
                    [pardic release];
                }
                [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"zan_success", nil) activityAnimated:NO duration:1.0];
            }else{
                aLabel.text = [NSString stringWithFormat:@"%d+",[[_broadcast valueForKey:@"share"]intValue]+1];
                if([self isHaveBroadcastTVC])
                {
                    NSMutableDictionary *pardic;
                    if(_isUserBroad)
                    {
                        pardic = [[NSMutableDictionary alloc]initWithDictionary:[MyAppDataManager.friendDos objectAtIndex:self.selectSection]];
                    }
                    else
                    {
                        pardic = [[NSMutableDictionary alloc]initWithDictionary:[MyAppDataManager.nearDos objectAtIndex:self.selectSection]];
                    }
                    NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:[pardic valueForKey:@"actioninfor"]];
                    
                    [dic setValue:[aLabel.text substringToIndex:aLabel.text.length-1] forKey:@"share"];
                    [pardic setValue:dic forKey:@"actioninfor"];
                    
                    if(_isUserBroad)
                    {
                        [MyAppDataManager.friendDos replaceObjectAtIndex:self.selectSection withObject:pardic];
                    }
                    else
                    {
                        [MyAppDataManager.nearDos replaceObjectAtIndex:self.selectSection withObject:pardic];
                    }
                    [dic release];
                    [pardic release];
                }
                
            }
        }
        //        else if (![resDic valueForKey:@"ok"])
        //        {
        //            NSArray * array=[[NSArray alloc]initWithArray:_praiseArr];
        //            for (NSDictionary * dict in array) {
        //                if ([[dict valueForKey:@"userid"] isEqualToString:MyAppDataManager.useruid]) {
        //                    [_praiseArr removeObject:dict];
        //                }
        //            }
        //            UILabel *aLabel = (UILabel *)[self.view viewWithTag:20];
        //            aLabel.text=[NSString stringWithFormat:@"%d",_praiseArr.count];
        //            [_broadTableView reloadData];
        //            [array release];
        //            //取消赞
        //            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:[NSString stringWithFormat:@"%@%@!",NSLocalizedString(@"cancelNotice", nil),NSLocalizedString(@"sendReply", nil)] activityAnimated:NO duration:1.0];
        //            //sendReply 发送  cancelNotice 取消
        //        }
        //
        else
        {
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"zan_failed", nil) activityAnimated:NO duration:1.0];
        }
    }
    
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Report_Broadcat])
    {
        //        NSLog(@"%@",resDic);
        if([[resDic valueForKey:@"ok"]boolValue]){
            
            if([self isHaveBroadcastTVC])
            {
                return;
            }
            if(_isUserBroad)
            {
                [MyAppDataManager.friendDos removeObjectAtIndex:self.selectSection];
                
            }
            else
            {
                [MyAppDataManager.nearDos removeObjectAtIndex:self.selectSection];
                
            }
            //将更新的广播列表更新到上个页面
            for(BanBu_BroadcastTVC  * broad in self.navigationController.viewControllers)
            {
                if([broad isKindOfClass:[BanBu_BroadcastTVC class]]||[broad isKindOfClass:[BanBu_PersonDataViewController class]])
                {
                    [broad.tableView reloadData];
                    break;
                }
            }
            
            
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"reportNotice", nil) activityAnimated:NO duration:1.0];
            
        }
    }
    
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Reply_Broadcast])
    {
        if([[resDic valueForKey:@"ok"]boolValue])
        {
            //            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"sendingNotice", nil) activityAnimated:YES];
            
            NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:1];
            [pars setValue:[_broadcast valueForKey:@"actid"] forKey:@"actid"];
            
            
            [AppComManager getBanBuData:BanBu_Get_Broadcast par:pars delegate:self];
            _isReplyed = YES;
        }
    }
    
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_Broadcast])
    {
        _downloadDic = [[NSMutableDictionary alloc]initWithDictionary:resDic];
        if([[resDic valueForKey:@"ok"]boolValue])
        {
            [replyList release];
            [_praiseArr removeAllObjects];
            [_praiseArr addObjectsFromArray:[resDic valueForKey:@"likelist"]];
            
            UILabel *aLab = (UILabel *)[self.view viewWithTag:20];
            {
                if([[aLab.text substringToIndex:aLab.text.length-1] integerValue]!=_praiseArr.count)
                {
                    aLab.text = [NSString stringWithFormat:@"%d",_praiseArr.count];
                }
            }
            
            replyList = [[NSArray alloc]initWithArray:[resDic valueForKey:@"replylist"]];
            [self.broadTableView reloadData];
            
            UILabel *aLabel = (UILabel *)[self.view viewWithTag:10];
            if(replyList.count>0){
                aLabel.text = [NSString stringWithFormat:@"%d+",replyList.count];
                
            }
            if(_isReplyed && replyList.count>0){
                [self.broadTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[replyList count] inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
                _isReplyed = NO;
            }
            
            NSMutableArray *replaceArr = [NSMutableArray arrayWithCapacity:0];
            for(int i=replyList.count-1;i>=0;i--){
                [replaceArr addObject:[replyList objectAtIndex:i]];
                if(replaceArr.count>=3){
                    break;
                }
            }
            
            NSLog(@"%@",self.navigationController.viewControllers);
            //将新的评论更新到上个页面
            UIViewController  * broad = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count - 2];
            if(([broad isKindOfClass:[BanBu_BroadcastTVC class]]||[broad isKindOfClass:[BanBu_PersonDataViewController class]]))
            {
                NSMutableDictionary *replaceDic;
                
                if(_isUserBroad)
                {
                    replaceDic = [MyAppDataManager.friendDos objectAtIndex:self.selectSection];
                    
                }
                else
                {
                    NSLog(@"MyAppDataManager.nearDos:%@",MyAppDataManager.nearDos);
                    replaceDic = [MyAppDataManager.nearDos objectAtIndex:self.selectSection];
                    
                }
                [replaceDic setValue:replaceArr forKey:@"replylist"];
                NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:[replaceDic valueForKey:@"actioninfor"]];
                [dic setValue:[NSString stringWithFormat:@"%d",replyList.count] forKey:@"comments"];
                [replaceDic setValue:dic forKey:@"actioninfor"];
                
                if(_isUserBroad)
                {
                    [MyAppDataManager.friendDos replaceObjectAtIndex:self.selectSection withObject:replaceDic];
                }
                else
                {
                    [MyAppDataManager.nearDos replaceObjectAtIndex:self.selectSection withObject:replaceDic];
                }
                [replaceDic setValue:[NSString stringWithFormat:@"%d",replyList.count] forKey:@"comments"];
                BanBu_BroadcastTVC * bbroad  = (BanBu_BroadcastTVC *)broad;
                [bbroad.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:self.selectSection inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
                //                break;
            }
            //            for(BanBu_BroadcastTVC  * broad in self.navigationController.viewControllers)
            //            {
            //                UIViewController * controller = [self.navigationController.viewControllers objectAtIndex:1];
            //                if(([broad isKindOfClass:[BanBu_BroadcastTVC class]]||[broad isKindOfClass:[BanBu_PersonDataViewController class]]))
            //                {
            //                    NSMutableDictionary *replaceDic;
            //
            //                    if(_isUserBroad)
            //                    {
            //                        replaceDic = [MyAppDataManager.friendDos objectAtIndex:self.selectSection];
            //
            //                    }
            //                    else
            //                    {
            //                        NSLog(@"MyAppDataManager.nearDos:%@",MyAppDataManager.nearDos);
            //                        replaceDic = [MyAppDataManager.nearDos objectAtIndex:self.selectSection];
            //
            //                    }
            //                    [replaceDic setValue:replaceArr forKey:@"replylist"];
            //                    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:[replaceDic valueForKey:@"actioninfor"]];
            //                    [dic setValue:[NSString stringWithFormat:@"%d",replyList.count] forKey:@"comments"];
            //                    [replaceDic setValue:dic forKey:@"actioninfor"];
            //
            //                    if(_isUserBroad)
            //                    {
            //                        [MyAppDataManager.friendDos replaceObjectAtIndex:self.selectSection withObject:replaceDic];
            //                    }
            //                    else
            //                    {
            //                        [MyAppDataManager.nearDos replaceObjectAtIndex:self.selectSection withObject:replaceDic];
            //                    }
            //                    [replaceDic setValue:[NSString stringWithFormat:@"%d",replyList.count] forKey:@"comments"];
            //
            //                    [broad.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:self.selectSection inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
            //                    break;
            //                }
            //            }
            
            return;
        }
    }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return YES;
}
- (void)textViewDidChange:(UITextView *)textView
{
    //    [textView setContentInset:UIEdgeInsetsMake(-2, 10, 0, -10)];
    
    self.placeHoldLabel.hidden = textView.text.length?YES:NO;
    
    
    CGFloat maxHeight = 179;
    CGFloat textViewContentHeight = textView.contentSize.height;
    textViewContentHeight = [textView sizeThatFits:CGSizeMake(textView.frame.size.width, maxHeight)].height;
    CGFloat changeInHeight = textViewContentHeight - self.previousTextViewContentHeight;
    NSLog(@"%f %f",textViewContentHeight,changeInHeight);
    
    changeInHeight = (self.previousTextViewContentHeight + changeInHeight >= maxHeight) ? 0.0f : changeInHeight;
    //    changeInHeight = (textViewContentHeight + changeInHeight >= maxHeight) ? 0.0f : changeInHeight;
    
    textView.contentInset =  UIEdgeInsetsMake(-3, 3, 0, -3);
    
    if(changeInHeight != 0.0f)
    {
        
        [UIView animateWithDuration:0.2f delay:0 options:(UIViewAnimationOptionAllowUserInteraction|
                                                          UIViewAnimationOptionBeginFromCurrentState) animations:^{
            //    CGFloat offset = textView.frame.size.height - textView.contentSize.height;
            //    textView.contentOffset = CGPointMake(0,-offset-3);
        } completion:^(BOOL finished) {
            
            inputViewFrame = self.chatView.frame;
            
            self.chatView.frame = CGRectMake(0.0f,
                                             inputViewFrame.origin.y - changeInHeight,
                                             inputViewFrame.size.width,
                                             inputViewFrame.size.height + changeInHeight);
            self.chatView.visibleContentView.frame = CGRectMake(0, 0, 320, self.chatView.frame.size.height);
            CGRect sendbuttonFrame  =  sendBtn.frame;
            sendbuttonFrame.origin.y = self.chatView.frame.size.height-38;
            sendBtn.frame = sendbuttonFrame;
            CGRect rect = textView.frame;
            rect.size.height +=changeInHeight;
            textView.frame = rect;
        }];
        
        
        //        [UIView animateWithDuration:0.01f
        //                         animations:^{
        //
        //                             CGFloat offset = textView.frame.size.height - textView.contentSize.height;
        //                             textView.contentOffset = CGPointMake(0,-offset-3);
        //                             NSLog(@"%lf",offset);
        //                                                      }
        //                         completion:^(BOOL finished) {
        //                             inputViewFrame = self.chatView.frame;
        //                             CGRect rect = textView.frame;
        //                             rect.size.height +=changeInHeight;
        //                             textView.frame = rect;
        //                             self.chatView.frame = CGRectMake(0.0f,
        //                                                              inputViewFrame.origin.y - changeInHeight,
        //                                                              inputViewFrame.size.width,
        //                                                              inputViewFrame.size.height + changeInHeight);
        //                             self.chatView.visibleContentView.frame = CGRectMake(0, 0, 320, self.chatView.frame.size.height);
        //
        //                             CGRect textAndSoundButtonFrame = _textAndSoundBtn.frame;
        //                             textAndSoundButtonFrame.origin.y = self.chatView.frame.size.height-38;
        //                             _textAndSoundBtn.frame =textAndSoundButtonFrame;
        //
        //                             CGRect sendbuttonFrame  =  sendBtn.frame;
        //                             sendbuttonFrame.origin.y = self.chatView.frame.size.height-38;
        //                             sendBtn.frame = sendbuttonFrame;
        //
        //
        //                      }];
        
        self.previousTextViewContentHeight = MIN(textViewContentHeight, maxHeight);
    }
    CGRect sendbuttonFrame  =  sendBtn.frame;
    sendbuttonFrame.origin.y = self.chatView.frame.size.height-38;
    sendBtn.frame = sendbuttonFrame;
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    [textView becomeFirstResponder];
    
    if(!self.previousTextViewContentHeight)
        
        self.previousTextViewContentHeight = textView.contentSize.height;
}

@end
